import copy
from functools import reduce


class Solution(object):
    def productExceptSelf(self, nums):
        n = len(nums)
        answer = [1] * n

        left_product = 1
        for i in range(n):
            answer[i] *= left_product
            left_product *= nums[i]
        
        right_product = 1
        for j in range(n-1, -1, -1):
            answer[j] *= right_product
            right_product *= nums[j]
        return answer

if __name__ == '__main__':
    s = Solution()
    print(s.productExceptSelf([1, 2, 3, 4]))
